#ifndef RC522_H
#define RC522_H

#include <Arduino.h>
#include <SPI.h>
#include <MFRC522.h>
#include <EEPROM.h>

#define SS_PIN          21
#define RST_PIN         22
#define EEPROM_SIZE     512
#define MAX_CARDS       10
#define CARD_SIZE       4
#define CARD_DATA_START 1        // 第0字节留给版本号
#define VERSION_ADDR    0
#define CURRENT_VERSION 0x01

enum CommandState {
    IDLE,
    WAITING_CARD
};

extern MFRC522 rfid;
extern CommandState currentState;
extern String inputCommand;
extern byte nuidPICC[4];

void printHex(byte *buffer, byte bufferSize);
void printDec(byte *buffer, byte bufferSize);
void handleSerialInput();
void readAndProcessCard();
void processCommand(String command);
void printAllRegisteredCards();
bool isCardRegistered(byte *uid);
bool registerCard(byte *uid);
void deleteAllCards();
bool deleteSingleCard(byte *uid);
String cardIdToString(byte *uid);
void sendCardStatusMQTT(byte *uid, bool isRegistered);
String getAllRegisteredCardsString();

#endif